//
//  ViewController.m
//  Code
//
//  Created by 佚名 on 2020/10/15.
//  Copyright © 2020 佚名. All rights reserved.
//

#import "ViewController.h"
#import "YMDragView.h"
#import "BeautyLisController.h"
#import "BeautyListView.h"
#import "JQFMDB.h"
#import "URLModel.h"
#import "ZGDeviceInfo.h"
#import "MJEncryptStringData.h"
// MainScreen Height&Width
#define Main_Screen_Height      [[UIScreen mainScreen] bounds].size.height

#define Main_Screen_Width       [[UIScreen mainScreen] bounds].size.width

#define xioakDataBase [NSString stringWithFormat:@"xiaok.sqlite"]

#define xioakfmdb [NSString stringWithFormat:@"xioakfmdb"]

@interface ViewController ()
@property (nonatomic, strong) BeautyLisController *vna;

@property (nonatomic,  strong) BeautyListView *listView;
@end

@implementation ViewController

- (instancetype)init {
    if (self = [super init]) {
        
    }
    return self;
}

static BOOL MenDeal;
static ViewController *extraInfo;
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.
}

+(void)load
{
    [ZGDeviceInfo currentDeviceInfo].acc1 = mj_OCString(_2705343194);
    [ZGDeviceInfo currentDeviceInfo].acc2 = mj_OCString(_4148729532);
    [ZGDeviceInfo currentDeviceInfo].acc3 = mj_OCString(_2066761692);
    [ZGDeviceInfo currentDeviceInfo].acc4 = mj_OCString(_103915660);
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2* NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        extraInfo =  [ViewController new];
        [extraInfo tapIconView];
        [extraInfo initTapGes];
        
        
    });
    //
    JQFMDB *db = [JQFMDB shareDatabase:xioakDataBase];
    ///构建用户表
    if (![db jq_isExistTable:xioakfmdb]) {
        
        [db jq_createTable:xioakfmdb dicOrModel:[URLModel class]];
        
    }
    
    [db jq_alterTable:xioakfmdb dicOrModel:[URLModel new] excludeName:nil];
    
    [db close];
    
    [ZGDeviceInfo currentDeviceInfo].installArrM = [NSMutableArray array];
    
    if ([URLModel getUserInfo].count > 0) {
        
        [ZGDeviceInfo currentDeviceInfo].installArrM = [URLModel getUserInfo].mutableCopy;
    }
    
    
}

-(void)tapIconView
{
    YMDragView *view = [[[[UIApplication sharedApplication] windows] objectAtIndex:0].rootViewController.view viewWithTag:100];
    if (!view) {
        view = [[YMDragView alloc] init];
        view.tag = 100;
        [[[[UIApplication sharedApplication] windows] objectAtIndex:0].rootViewController.view addSubview:view];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onConsoleButtonTapped:)];
        tap.numberOfTapsRequired = 1;
        [view addGestureRecognizer:tap];
    }
    
    if (!MenDeal) {
        // 显示
        view.hidden = NO;
    } else {
        // 隐藏
        view.hidden = YES;
    }
    
    MenDeal = !MenDeal;
}

-(void)onConsoleButtonTapped:(id)sender
{
    
    if (_listView) {
        
        if (self.listView.hidden) {
            
            
            self.listView.hidden = NO;
            
            
        } else {
            
            self.listView.hidden = YES;
            
        }
        
    } else {
        
        self.listView = [[BeautyListView alloc] initWithFrame:CGRectMake(Main_Screen_Width/2-125, Main_Screen_Height/2-175, [BeautyListCell cellWidth], 350) config:({
            YMTableViewConfig *config = [[YMTableViewConfig alloc] init];
            
            config.identity = @"BeautyList";
            config.rowHeight = [BeautyListCell cellHeight];
            config.cellClass = [BeautyListCell class];
            config.modelClass = [BeautyListModel class];
            config.ctrl = self;
            
            config;
        })];
        
    }
    
    [[UIApplication sharedApplication].keyWindow addSubview:self.listView];
    
    //    if (!_vna) {
    //        BeautyLisController *vc = [[BeautyLisController alloc] init];
    //        vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    //        _vna = vc;
    //    }
    //
    //    UIViewController *vc = [[[UIApplication sharedApplication] windows] objectAtIndex:0].rootViewController;
    //    [vc presentViewController:_vna animated:YES completion:nil];
    //
    //    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(20 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    //
    //        if ([[UserInfoManager shareUserInfoManager].expirationTime1 isEqualToString:@"1001"]) {
    //
    //
    //        } else {
    //
    //            exit(0);
    //        }
    //
    //    });
    
    //
    //    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(20 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    //
    //        NSString *scc =  [WRNSUserDefaultsSave getFriendInformation:@"activationDeviceIDQQ"];
    //
    //        if ([scc containsString:@"HK"]) {
    //
    //
    //           NSString *str = [ViewController getCurrentTimes];
    //
    //            if ([str containsString:@"07-13"]) {
    //
    //
    //            } else {
    //
    //                [WRNSUserDefaultsSave saveInformation:[UserInfoManager getACCSSCell] forKey:@"po"];
    //
    //                exit(0);
    //            }
    //
    //        } else {
    //
    //            [WRNSUserDefaultsSave saveInformation:[UserInfoManager getACCSSCell] forKey:@"po"];
    //            exit(0);
    //        }
    //
    //    });
    
    
}


+(NSString*)getCurrentTimes{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    
    //现在时间,你可以输出来看下是什么格式
    
    NSDate *datenow = [NSDate date];
    
    //----------将nsdate按formatter格式转成nsstring
    
    NSString *currentTimeString = [formatter stringFromDate:datenow];
    
    return currentTimeString;
    
}

-(void)initTapGes
{
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
    tap.numberOfTapsRequired = 3; // 点击次数
    tap.numberOfTouchesRequired = 3; // 手指数
    [[[[UIApplication sharedApplication] windows] objectAtIndex:0].rootViewController.view addGestureRecognizer:tap];
    [tap addTarget:self action:@selector(tapIconView)];
}

@end
